/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.taobao.ibatiside.model.configv2.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.taobao.ibatiside.model.configv2.Configv2Package;
import org.taobao.ibatiside.model.configv2.DataSourceType;
import org.taobao.ibatiside.model.configv2.PropertyType;
import org.taobao.ibatiside.model.configv2.TransactionManagerType;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Transaction Manager Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.taobao.ibatiside.model.configv2.impl.TransactionManagerTypeImpl#getProperty <em>Property</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.configv2.impl.TransactionManagerTypeImpl#getDataSource <em>Data Source</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.configv2.impl.TransactionManagerTypeImpl#isCommitRequired <em>Commit Required</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.configv2.impl.TransactionManagerTypeImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TransactionManagerTypeImpl extends EObjectImpl implements TransactionManagerType {
	/**
	 * The cached value of the '{@link #getProperty() <em>Property</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProperty()
	 * @generated
	 * @ordered
	 */
	protected EList<PropertyType> property;

	/**
	 * The cached value of the '{@link #getDataSource() <em>Data Source</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataSource()
	 * @generated
	 * @ordered
	 */
	protected DataSourceType dataSource;

	/**
	 * The default value of the '{@link #isCommitRequired() <em>Commit Required</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCommitRequired()
	 * @generated
	 * @ordered
	 */
	protected static final boolean COMMIT_REQUIRED_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isCommitRequired() <em>Commit Required</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCommitRequired()
	 * @generated
	 * @ordered
	 */
	protected boolean commitRequired = COMMIT_REQUIRED_EDEFAULT;

	/**
	 * This is true if the Commit Required attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean commitRequiredESet;

	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final Object TYPE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected Object type = TYPE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TransactionManagerTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Configv2Package.Literals.TRANSACTION_MANAGER_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PropertyType> getProperty() {
		if (property == null) {
			property = new EObjectContainmentEList<PropertyType>(PropertyType.class, this, Configv2Package.TRANSACTION_MANAGER_TYPE__PROPERTY);
		}
		return property;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataSourceType getDataSource() {
		return dataSource;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDataSource(DataSourceType newDataSource, NotificationChain msgs) {
		DataSourceType oldDataSource = dataSource;
		dataSource = newDataSource;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE, oldDataSource, newDataSource);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDataSource(DataSourceType newDataSource) {
		if (newDataSource != dataSource) {
			NotificationChain msgs = null;
			if (dataSource != null)
				msgs = ((InternalEObject)dataSource).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE, null, msgs);
			if (newDataSource != null)
				msgs = ((InternalEObject)newDataSource).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE, null, msgs);
			msgs = basicSetDataSource(newDataSource, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE, newDataSource, newDataSource));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isCommitRequired() {
		return commitRequired;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCommitRequired(boolean newCommitRequired) {
		boolean oldCommitRequired = commitRequired;
		commitRequired = newCommitRequired;
		boolean oldCommitRequiredESet = commitRequiredESet;
		commitRequiredESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Configv2Package.TRANSACTION_MANAGER_TYPE__COMMIT_REQUIRED, oldCommitRequired, commitRequired, !oldCommitRequiredESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void unsetCommitRequired() {
		boolean oldCommitRequired = commitRequired;
		boolean oldCommitRequiredESet = commitRequiredESet;
		commitRequired = COMMIT_REQUIRED_EDEFAULT;
		commitRequiredESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET, Configv2Package.TRANSACTION_MANAGER_TYPE__COMMIT_REQUIRED, oldCommitRequired, COMMIT_REQUIRED_EDEFAULT, oldCommitRequiredESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetCommitRequired() {
		return commitRequiredESet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(Object newType) {
		Object oldType = type;
		type = newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Configv2Package.TRANSACTION_MANAGER_TYPE__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Configv2Package.TRANSACTION_MANAGER_TYPE__PROPERTY:
				return ((InternalEList<?>)getProperty()).basicRemove(otherEnd, msgs);
			case Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE:
				return basicSetDataSource(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Configv2Package.TRANSACTION_MANAGER_TYPE__PROPERTY:
				return getProperty();
			case Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE:
				return getDataSource();
			case Configv2Package.TRANSACTION_MANAGER_TYPE__COMMIT_REQUIRED:
				return isCommitRequired();
			case Configv2Package.TRANSACTION_MANAGER_TYPE__TYPE:
				return getType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Configv2Package.TRANSACTION_MANAGER_TYPE__PROPERTY:
				getProperty().clear();
				getProperty().addAll((Collection<? extends PropertyType>)newValue);
				return;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE:
				setDataSource((DataSourceType)newValue);
				return;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__COMMIT_REQUIRED:
				setCommitRequired((Boolean)newValue);
				return;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__TYPE:
				setType(newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Configv2Package.TRANSACTION_MANAGER_TYPE__PROPERTY:
				getProperty().clear();
				return;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE:
				setDataSource((DataSourceType)null);
				return;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__COMMIT_REQUIRED:
				unsetCommitRequired();
				return;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__TYPE:
				setType(TYPE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Configv2Package.TRANSACTION_MANAGER_TYPE__PROPERTY:
				return property != null && !property.isEmpty();
			case Configv2Package.TRANSACTION_MANAGER_TYPE__DATA_SOURCE:
				return dataSource != null;
			case Configv2Package.TRANSACTION_MANAGER_TYPE__COMMIT_REQUIRED:
				return isSetCommitRequired();
			case Configv2Package.TRANSACTION_MANAGER_TYPE__TYPE:
				return TYPE_EDEFAULT == null ? type != null : !TYPE_EDEFAULT.equals(type);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (commitRequired: ");
		if (commitRequiredESet) result.append(commitRequired); else result.append("<unset>");
		result.append(", type: ");
		result.append(type);
		result.append(')');
		return result.toString();
	}

} //TransactionManagerTypeImpl
